package cn.xs.surveypark.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.xs.surveypark.dao.BaseDao;
import cn.xs.surveypark.domain.Page;
import cn.xs.surveypark.domain.Survey;
import cn.xs.surveypark.domain.User;
import cn.xs.surveypark.service.SurveyService;

/**
 * SurveyServiceImpl
 * @author Administrator
 *
 */
@Service("surveyService")
public class SurveyServiceImpl implements SurveyService {

	//注入surveyDao
	@Resource(name="surveyDao")
	private BaseDao<Survey> surveyDao;
	
	//注入pageDao
	@Resource(name="pageDao")
	private BaseDao<Page> pageDao;
	
	@Override
	public Survey newSurvey(User u) {
		// TODO Auto-generated method stub
		Survey s= new Survey();
		Page p = new Page();
		p.setSurvey(s);
		s.getPages().add(p);
		//设置用户和调查的关系
		s.setUser(u);
		//保存
		surveyDao.saveEntity(s);
		pageDao.saveEntity(p);
		return s;
	}

	@Override
	public List<Survey> findMySurvey(User user) {
		String hql = "from Survey s where s.user.id = ?";
		return surveyDao.findgetEntityHQL(hql, user.getId());
	}

}
